home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_058 / newzap / sources / beep.c next >
C/C++ Source or Header  |  1992-05-06  |  2KB  |  57 lines

  1. /* BEEP.C - NewZAP support routines - (c) 1986 John Hodgson */
  2.  
  3. /* Absolute bare minimum beep routine. Allocates/deallocates all resources
  4.    during entry & exit. Very easy to spruce up! */
  5.  
  6. #define SOUNDPRIORITY 50; /* completely arbitrary */
  7.  
  8. extern struct Window *pwindow; /* so we can find the Workbench screen */
  9.  
  10. Beep()
  11. {
  12.   struct IOAudio audioblock;
  13.   struct MsgPort *replyport=0,*CreatePort();
  14.  
  15.   static UBYTE wave[] = {~127,~127,127,127}; /* cheapo square wave */
  16.   static UBYTE allocmap[] = {1,2,4,8}; /* any available channel */
  17.  
  18.   long OpenDevice(),WaitIO();
  19.   UBYTE *wavesample;
  20.  
  21.   setmem(&audioblock,sizeof(audioblock),0); /* start fresh */
  22.  
  23.   if ((replyport=CreatePort(0L,0L))==0) {
  24.     DisplayBeep(pwindow->WScreen); /* flash if can't beep */
  25.     return(0);
  26.   }
  27.  
  28.   /* prepare for ALLOCATE */
  29.   
  30.   audioblock.ioa_Data=&allocmap[0];
  31.   audioblock.ioa_Length=sizeof(allocmap);
  32.   audioblock.ioa_Request.io_Message.mn_ReplyPort=replyport;
  33.   audioblock.ioa_Request.io_Message.mn_Node.ln_Pri=SOUNDPRIORITY;
  34.  
  35.   /* attempt to ADCMD_ALLOCATE while opening */
  36.  
  37.   if (OpenDevice("audio.device",0L,&audioblock,0L)) {
  38.     DeletePort(replyport);
  39.     DisplayBeep(pwindow->WScreen);
  40.     return(0); /* back if no channel available */
  41.   }
  42.  
  43.   audioblock.ioa_Request.io_Command=CMD_WRITE;
  44.   audioblock.ioa_Request.io_Flags=ADIOF_PERVOL;
  45.   audioblock.ioa_Period=447; /* 2000 Hz for this waveform */
  46.   audioblock.ioa_Volume=64/2; /* half volume */
  47.   audioblock.ioa_Cycles=150; /* 1/15 sec. */
  48.   audioblock.ioa_Data=&wave[0];
  49.   audioblock.ioa_Length=sizeof(wave);
  50.  
  51.   BeginIO(&audioblock);
  52.   if (WaitIO(&audioblock)) DisplayBeep(pwindow->WScreen);
  53.  
  54.   CloseDevice(&audioblock); /* clean up now */
  55.   DeletePort(audioblock.ioa_Request.io_Message.mn_ReplyPort);
  56. }
  57.